package com.site.wisdom_construction.controller.personnelModule;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.personnelModule.EducationLiabilityStatementService;
import com.site.wisdom_construction.util.TimeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/3/28
 * @Description
 */
@Api(tags = "安全责任书接口")
@RestController
@RequestMapping("EducationLiabilityStatement")
@CrossOrigin
public class EducationLiabilityStatementController {
    @Autowired
    private EducationLiabilityStatementService educationLiabilityStatementService;

    @ApiOperation(value = "增加安全责任书", notes = "测试数据:")
    @PostMapping("/insertEducationLiabilityStatement")
    public JsonResult insertEducationLiabilityStatement(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        map.put("updateDate", TimeUtils.getNowTime());
        int i = educationLiabilityStatementService.insertEducationLiabilityStatement(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功录入安全责任书!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("录入安全责任书失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除安全责任书", notes = "测试数据:")
    @PostMapping("/deleteEducationLiabilityStatement")
    public JsonResult deleteEducationLiabilityStatement(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        List<Integer> list = (List<Integer>) map.get("list");
        int l = 0;
        Map mapR = new HashMap();
        for (int i = 0;i<list.size();i++){
            mapR.put("id",list.get(i));
            int a = educationLiabilityStatementService.deleteEducationLiabilityStatement(mapR);
            l+=a;
        }
        if (l>=1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除安全责任书!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除安全责任书失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "修改安全责任书", notes = "测试数据:")
    @PostMapping("/updateEducationLiabilityStatement")
    public JsonResult updateEducationLiabilityStatement(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        map.put("updateDate", TimeUtils.getNowTime());
        int i = educationLiabilityStatementService.updateEducationLiabilityStatement(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功修改安全责任书!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("修改安全责任书失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页模糊查询安全责任书", notes = "测试数据:")
    @PostMapping("/findEducationLiabilityStatementByPage")
    public Page findEducationLiabilityStatementByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(educationLiabilityStatementService.Total(map));
        page.setItems(educationLiabilityStatementService.findEducationLiabilityStatementByPage(map));
        return page;
    }

    @ApiOperation(value = "根据id查询安全责任书", notes = "测试数据:")
    @PostMapping("/findEducationLiabilityStatementById")
    public OneDataResult findEducationLiabilityStatementById(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(educationLiabilityStatementService.findEducationLiabilityStatementById(map));
        return oneDataResult;
    }

    @ApiOperation(value = "下拉框查询全部安全责任书", notes = "测试数据:")
    @PostMapping("/selectEducationLiabilityStatement")
    public OneDataResult selectEducationLiabilityStatement(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(educationLiabilityStatementService.selectEducationLiabilityStatement(map));
        return oneDataResult;
    }
}
